
# generate figure 4

library(rio) # to load data
library(tidyverse) # to reshape data
library(lmtest) # to cluster standard errors
library(sandwich) # to cluster standard errors
library(ggeffects) # to plot results

# set your working directory
setwd("~/replication_files")

# load models
source("03_generate_table1.R")

# make predictions with clustered standard errors
# based on model 4 of table 1

# figure 4
predictions2 <- ggpredict(probit4, terms = c("log_oil_production_lag","iso3c[all]"), vcov_fun = "vcovHC",
                          vcov_type = "HC0", 
                          vcov_args = list(cluster = monthly_data$iso3c))
plot(predictions2, grid = T) +
  scale_fill_manual(values=c("#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000",
                             "#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000",
                             "#000000","#000000")) + 
  scale_color_manual(values=c("#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000",
                              "#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000",
                              "#000000","#000000")) + 
  labs(y = "Predicted Probability of Debt Issuance", x = bquote(`Ln Oil and Gas Production `[t-1]),
       title = " ") + theme_classic() +
  theme(axis.text = element_text(size = 12), plot.title = element_text(face = "bold"),
        axis.title = element_text(size = 12)) + scale_x_continuous(breaks = pretty_breaks())

ggsave("figures/figure4.pdf", height = 10, width = 8)
